package rmmk.zadanie2;

public class Binary implements ISearch {

	public int find(int number, int[] array) {
		int leftIndex = 0, rightIndex = array.length-1;
		
		while(leftIndex <= rightIndex)
		{
			int center = (leftIndex + rightIndex) / 2;
			
			if(number == array[center]) return center;
			else{
				if(array[center] < number)
					leftIndex = center+1;
				else rightIndex = center - 1;
			}
		}
		
		return -1;
	}

}
